package com.media.entrance.controller;

import com.media.entrance.mapper.MatchMapper;
import com.media.entrance.model.MatchInfo;
import com.media.entrance.service.MatchService;
import com.media.entrance.service.OperateDatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

// pg数据库CRUD测试
@Deprecated
@RestController
public class MatchController {
    @Autowired
    private OperateDatabaseService operateDatabaseService;

    @GetMapping("/matchinfo/{agentId}")
    public MatchInfo getMatchInfo(@PathVariable("agentId") String agentId) {
        return operateDatabaseService.findByAgentId(agentId);
    }

    @DeleteMapping("/matchinfo/{agentId}")
    public int deleteMatchInfo(@PathVariable("agentId") String agentId) {
        return operateDatabaseService.deleteByAgentId(agentId);
    }

    @PutMapping("/matchinfo/{agentId}")
    public int updateMatchInfo(@RequestBody MatchInfo matchinfo) {
        Date time = new Date();
        matchinfo.setTimestamp(time);
        return operateDatabaseService.updateMatchInfo(matchinfo);
    }

    @PostMapping("/matchinfo")
    public MatchInfo insertMatchinfo(@RequestBody MatchInfo matchinfo) {
        int count = operateDatabaseService.insertMatchInfo(matchinfo);
        if (count > 0) {
            System.out.println("插入数据成功");
        }
        return matchinfo;
    }
}

